import win32clipboard as w 
import win32con
import os

def getText(): 
    w.OpenClipboard() 
    d=w.GetClipboardData(win32con.CF_TEXT) 
    w.CloseClipboard() 
    return d 
 
def setText(aString): 
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(win32con.CF_TEXT,aString) 
    w.CloseClipboard()

pwfile = os.path.expanduser('~/lazypass.txt')

import sys

def main():
    if not os.path.isfile(pwfile):
        open(pwfile,'w').write(
            "# uid password Description\n######################\n")
    
    if len(sys.argv) == 1:
        os.startfile(pwfile)
        return
    
    scanword = sys.argv[1]
    lines = open(pwfile).readlines()
    
    matches = [l for l in lines if scanword.lower() in l.lower()]
    if not matches:
        print "No match"
        return
    if len(matches) > 1:
        print "\n".join(matches)
    
    uid, pw, desc = matches[0].split(None,2)
    setText(pw)
    print 'Pasted passwd to clipboard: [%s]: %s ' % (uid, desc)

main()